﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace ExcelInteropTest
{
    public partial class Form1 : Form
    { 
        private Microsoft.Office.Interop.Excel.Application app = null;
        private Microsoft.Office.Interop.Excel.Workbook workbook = null;
        private Microsoft.Office.Interop.Excel.Worksheet worksheet = null;
        private Microsoft.Office.Interop.Excel.Range workSheet_range = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            var excell_app = new ExcelHelper();

            //creates the main header
            //excell_app.createHeaders(5, 2, "Total of Products", "B5", "D5", 2, "YELLOW", true, 10, "n");
            //creates subheaders
            excell_app.createHeaders(1, 1, "Sales Person", "A1", "A1", 0, "", true, 10, "");
            excell_app.createHeaders(1, 2, "Opt in", "B1", "B1", 0, "", true, 10, "");
            excell_app.createHeaders(1, 3, "Opt out", "C1", "C1", 0, "", true, 10, "");
            excell_app.createHeaders(1, 4, "No email", "D1", "D1", 0, "", true, 10, "");
            excell_app.createHeaders(1, 5, "Total", "E1", "E1", 0, "", true, 10, "");

            //add Data to to cells
            int row = 0, col = 0;
            row = 2;
            excell_app.addData(row, 1, "Erik Corzberg", "A2", "A2", "");
            excell_app.addData(row, 2, "500", "B2", "B2", "#,##0");
            excell_app.addData(row, 3, "30", "C2", "C2", "#,##0");
            excell_app.addData(row, 4, "40", "D2", "D2", "#,##0");
            excell_app.addData(row, 5, "570", "E2", "E2", "#,##0");

            row = 3;
            excell_app.addData(row, 1, "Michelle Estrin", "A3", "A3", "");
            excell_app.addData(row, 2, "490", "B3", "B3", "#,##0");
            excell_app.addData(row, 3, "20", "C3", "C3", "#,##0");
            excell_app.addData(row, 4, "50", "D3", "D3", "#,##0");
            excell_app.addData(row, 5, "560", "E3", "E3", "#,##0");

            row = 4;
            excell_app.addData(row, 1, "John Smith", "A4", "A4", "");
            excell_app.addData(row, 2, "1400", "B4", "B4", "#,##0");
            excell_app.addData(row, 3, "23", "C4", "C4", "#,##0");
            excell_app.addData(row, 4, "100", "D4", "D4", "#,##0");
            excell_app.addData(row, 5, "1523", "E4", "E4", "#,##0");

            excell_app.addChart();
            excell_app.save();

            //_Worksheet sheet = null;  //(assume this is a reference to a valid _Worksheet object)  
            //ChartObjects charts = (ChartObjects)sheet.ChartObjects(Type.Missing);  
            //ChartObject chartObject = (ChartObject)charts.Add(10, 80, 300, 250);  
            //Chart chart = chartObject.Chart;  
            //chart.ChartType = XlChartType.xlXYScatter;
        }
    }
}
